#include "bits/stdc++.h"
#include <unordered_set>

using namespace std;

unordered_set<int> s;

const int N = 8;
int n,m,k;
int w[N][N];

int dx[4] = {-1, 0, 1, 0}, dy[4] = {0, 1, 0, -1};

void dfs(int x, int y, int c, int num) {
    if (x < 1 || x > n || y < 1 || y > m) return;

    if (c == k+1) {
        s.insert(num);
    } else {
        for (int i=0; i<4; i++) {
            dfs(x+dx[i], y+dy[i], c+1, num*10+w[x+dx[i]][y+dy[i]]);
        }
    }
}
int main() {
    cin >> n >> m >> k;

    for (int i=1; i<=n; i++) {
        for (int j=1; j<=m; j++) {
            cin >> w[i][j];
        }
    }

    for (int i=1; i<=n; i++) {
        for (int j=1; j<=m; j++) {
            dfs(i,j,1,w[i][j]);
        }
    }

    cout << s.size() << endl;
    return 0;
}